package dto;

import dao.UserDao;
import domain.User;
import org.springframework.util.StringUtils;

/**
 * Created by zhifu on 2015/3/24.
 */
public class UserDto {
    private String name;
    private String email;
    private Integer  age;
    private String guid;

    public UserDto(){}

    public  UserDto(User user){
        name = user.getName();
        email = user.getEmail();
        age = user.getAge();
        guid = user.getGuid();
    }

    public User toUser(UserDao userDao){
        User user;
        if(StringUtils.hasText(guid)){
            user = userDao.findUserByGuid(guid);
            user.update(this);
        }else{
            user = new User(this);
        }
        return user;
    }

    public String getName() {
        return name;
    }

    public String getEmail() {
        return email;
    }

    public Integer getAge() {
        return age;
    }

    @Override
    public String toString() {
        return name + " " +email +" "+ age;
    }

    public String getGuid() {
        return guid;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }
}
